<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text">
<input type="button" value="平方" onclick="f()">
<input type="button" value="求和" onclick="f1()">
<div>结果:</div>

<script>
    let l=document.querySelector("input");
    let o=document.querySelector("div");

    function f() {
        if (isNaN(l.value)){
            o.innerText="输入错误";
            return;
        }
        o.innerText="结果:"+l.value*l.value;
    }
    function f1() {
        //当字符串进行-*/运算时会自动将字符串转成数值
        if (isNaN(l.value)){
            o.innerText="输入错误";
            return;
        }

        o.innerText="结果:"+(parseFloat(l.value)+parseFloat(l.value));
    }

</script>


</body>
</html>